//
//  NSDictionary-MutableDeepCopy.m
//  08grouped
//
//  Created by Rocky Xu on 12-8-22.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "NSDictionary-MutableDeepCopy.h"

@implementation NSDictionary(MutableDeepCopy)

-(NSMutableDictionary *) mutableDeepCopy{
    NSMutableDictionary *returnDict = [[NSMutableDictionary alloc]initWithCapacity:[self count]];
    NSArray *keys = [self allKeys];
    for(id key in keys){
        id oneValue = [self valueForKey:key];
        id oneCopy = nil;
        
        if([oneValue respondsToSelector:@selector(mutableDeepCopy)])
            oneCopy = [oneValue mutableDeepCopy];
        else if([oneCopy respondsToSelector:@selector(mutableCopy)])
            oneCopy = [oneValue mutableCopy];
        if(oneCopy == nil)
            oneCopy = [oneValue copy];
        [returnDict setValue:oneCopy forKey:key];
        [oneValue release];
    }
    return returnDict;
    
}

@end
